﻿
namespace Indeco.G24.Windows.Forms
{
	/// <summary>
	/// abstract TinTucChuDe typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class TinTucChuDeDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<TinTucChuDeDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.TinTucChuDe _currentTinTucChuDe = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxTinTucChuDeDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxTinTucChuDeErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxTinTucChuDeBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the IDTinTucChuDe property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDTinTucChuDeDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the TenChuDe property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxTenChuDeDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ThoiDiemChinhSua property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxThoiDiemChinhSuaDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ThoiDiemCapNhat property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxThoiDiemCapNhatDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.TinTucChuDe> _TinTucChuDeList;
				
		/// <summary> 
		/// The list of TinTucChuDe to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.TinTucChuDe> TinTucChuDeList
		{
			get {return this._TinTucChuDeList;}
			set
			{
				this._TinTucChuDeList = value;
				this.uxTinTucChuDeBindingSource.DataSource = null;
				this.uxTinTucChuDeBindingSource.DataSource = value;
				this.uxTinTucChuDeDataGridView.DataSource = null;
				this.uxTinTucChuDeDataGridView.DataSource = this.uxTinTucChuDeBindingSource;				
				//this.uxTinTucChuDeBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxTinTucChuDeBindingSource_ListChanged);
				this.uxTinTucChuDeBindingSource.CurrentItemChanged += new System.EventHandler(OnTinTucChuDeBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnTinTucChuDeBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentTinTucChuDe = uxTinTucChuDeBindingSource.Current as Entities.TinTucChuDe;
			
			if (_currentTinTucChuDe != null)
			{
				_currentTinTucChuDe.Validate();
			}
			//_TinTucChuDe.Validate();
			OnCurrentEntityChanged();
		}

		//void uxTinTucChuDeBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.TinTucChuDe"/> instance.
		/// </summary>
		public Entities.TinTucChuDe SelectedTinTucChuDe
		{
			get {return this._currentTinTucChuDe;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxTinTucChuDeDataGridView.VirtualMode;}
			set
			{
				this.uxTinTucChuDeDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxTinTucChuDeDataGridView.AllowUserToAddRows;}
			set {this.uxTinTucChuDeDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxTinTucChuDeDataGridView.AllowUserToDeleteRows;}
			set {this.uxTinTucChuDeDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxTinTucChuDeDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxTinTucChuDeDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="TinTucChuDeDataGridViewBase"/> class.
		/// </summary>
		public TinTucChuDeDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxTinTucChuDeDataGridView = new System.Windows.Forms.DataGridView();
			this.uxTinTucChuDeBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxTinTucChuDeErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDTinTucChuDeDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxTenChuDeDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxThoiDiemChinhSuaDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxThoiDiemCapNhatDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucChuDeDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucChuDeBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucChuDeErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxTinTucChuDeErrorProvider
			// 
			this.uxTinTucChuDeErrorProvider.ContainerControl = this;
			this.uxTinTucChuDeErrorProvider.DataSource = this.uxTinTucChuDeBindingSource;						
			// 
			// uxTinTucChuDeDataGridView
			// 
			this.uxTinTucChuDeDataGridView.AutoGenerateColumns = false;
			this.uxTinTucChuDeDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxTinTucChuDeDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDTinTucChuDeDataGridViewColumn,
		this.uxTenChuDeDataGridViewColumn,
		this.uxThoiDiemChinhSuaDataGridViewColumn,
		this.uxThoiDiemCapNhatDataGridViewColumn			});
			this.uxTinTucChuDeDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxTinTucChuDeDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxTinTucChuDeDataGridView.Name = "uxTinTucChuDeDataGridView";
			this.uxTinTucChuDeDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxTinTucChuDeDataGridView.TabIndex = 0;	
			this.uxTinTucChuDeDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxTinTucChuDeDataGridView.EnableHeadersVisualStyles = false;
			this.uxTinTucChuDeDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnTinTucChuDeDataGridViewDataError);
			this.uxTinTucChuDeDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnTinTucChuDeDataGridViewCellValueNeeded);
			this.uxTinTucChuDeDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnTinTucChuDeDataGridViewCellValuePushed);
			
			//
			// uxIDTinTucChuDeDataGridViewColumn
			//
			this.uxIDTinTucChuDeDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDTinTucChuDeDataGridViewColumn.DataPropertyName = "IDTinTucChuDe";
			this.uxIDTinTucChuDeDataGridViewColumn.HeaderText = "IDTinTucChuDe";
			this.uxIDTinTucChuDeDataGridViewColumn.Name = "uxIDTinTucChuDeDataGridViewColumn";
			this.uxIDTinTucChuDeDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDTinTucChuDeDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDTinTucChuDeDataGridViewColumn.ReadOnly = false;		
			//
			// uxTenChuDeDataGridViewColumn
			//
			this.uxTenChuDeDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxTenChuDeDataGridViewColumn.DataPropertyName = "TenChuDe";
			this.uxTenChuDeDataGridViewColumn.HeaderText = "TenChuDe";
			this.uxTenChuDeDataGridViewColumn.Name = "uxTenChuDeDataGridViewColumn";
			this.uxTenChuDeDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxTenChuDeDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxTenChuDeDataGridViewColumn.ReadOnly = false;		
			//
			// uxThoiDiemChinhSuaDataGridViewColumn
			//
			this.uxThoiDiemChinhSuaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxThoiDiemChinhSuaDataGridViewColumn.DataPropertyName = "ThoiDiemChinhSua";
			this.uxThoiDiemChinhSuaDataGridViewColumn.HeaderText = "ThoiDiemChinhSua";
			this.uxThoiDiemChinhSuaDataGridViewColumn.Name = "uxThoiDiemChinhSuaDataGridViewColumn";
			this.uxThoiDiemChinhSuaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxThoiDiemChinhSuaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxThoiDiemChinhSuaDataGridViewColumn.ReadOnly = false;		
			//
			// uxThoiDiemCapNhatDataGridViewColumn
			//
			this.uxThoiDiemCapNhatDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxThoiDiemCapNhatDataGridViewColumn.DataPropertyName = "ThoiDiemCapNhat";
			this.uxThoiDiemCapNhatDataGridViewColumn.HeaderText = "ThoiDiemCapNhat";
			this.uxThoiDiemCapNhatDataGridViewColumn.Name = "uxThoiDiemCapNhatDataGridViewColumn";
			this.uxThoiDiemCapNhatDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxThoiDiemCapNhatDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxThoiDiemCapNhatDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxTinTucChuDeDataGridView);
			this.Name = "TinTucChuDeDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucChuDeErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucChuDeDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucChuDeBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				TinTucChuDeDataGridViewEventArgs args = new TinTucChuDeDataGridViewEventArgs();
				args.TinTucChuDe = _currentTinTucChuDe;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class TinTucChuDeDataGridViewEventArgs : System.EventArgs
		{
			private Entities.TinTucChuDe	_TinTucChuDe;
	
			/// <summary>
			/// the  Entities.TinTucChuDe instance.
			/// </summary>
			public Entities.TinTucChuDe TinTucChuDe
			{
				get { return _TinTucChuDe; }
				set { _TinTucChuDe = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxTinTucChuDeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnTinTucChuDeDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxTinTucChuDeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnTinTucChuDeDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxTinTucChuDeDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDTinTucChuDeDataGridViewColumn":
						e.Value = TinTucChuDeList[e.RowIndex].IDTinTucChuDe;
						break;
					case "uxTenChuDeDataGridViewColumn":
						e.Value = TinTucChuDeList[e.RowIndex].TenChuDe;
						break;
					case "uxThoiDiemChinhSuaDataGridViewColumn":
						e.Value = TinTucChuDeList[e.RowIndex].ThoiDiemChinhSua;
						break;
					case "uxThoiDiemCapNhatDataGridViewColumn":
						e.Value = TinTucChuDeList[e.RowIndex].ThoiDiemCapNhat;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxTinTucChuDeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnTinTucChuDeDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxTinTucChuDeDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDTinTucChuDeDataGridViewColumn":
						TinTucChuDeList[e.RowIndex].IDTinTucChuDe = (System.Guid)e.Value;
						break;
					case "uxTenChuDeDataGridViewColumn":
						TinTucChuDeList[e.RowIndex].TenChuDe = (System.String)e.Value;
						break;
					case "uxThoiDiemChinhSuaDataGridViewColumn":
						TinTucChuDeList[e.RowIndex].ThoiDiemChinhSua = (System.DateTime)e.Value;
						break;
					case "uxThoiDiemCapNhatDataGridViewColumn":
						TinTucChuDeList[e.RowIndex].ThoiDiemCapNhat = (System.DateTime)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
